package com.itheima.dao;

import com.github.pagehelper.Page;
import com.itheima.pojo.Permission;
import org.apache.ibatis.annotations.*;

import java.util.Set;

public interface PermissionDao {
    @Select("select * from t_role_permission trp,t_permission p where trp.permission_id=p.id and role_id=#{id}")
    Set<Permission> findPermissionsByRid(Integer id);
    @Select("select * from t_permission where name like #{condition} or keyword  like #{condition}")
    Page<Permission> findByPage(String condition);
     @Select("select * from t_permission where keyword=#{keyword} and id!=#{id}")
    Permission checkIsRepKey(@Param("keyword") String keyword, @Param("id")Integer id);
    @Select("select * from t_permission where keyword=#{keyword}")
    Permission checkIsRepByKeyWord(String keyword);
    @Update("update t_permission set name=#{name},keyword=#{keyword},description=#{description} where id=#{id}")
    void deit(Permission permission);
     @Select("select * from t_permission where id=#{id}")
    Permission findPermissionById(Integer id);
     @Insert("insert into t_permission(name,keyword,description) values(#{name},#{keyword},#{description})")
     @Options(useGeneratedKeys = true,keyProperty = "id",keyColumn = "id")
    void addPermission(Permission permission);
     @Select("select role_id from    t_role_permission WHERE permission_id=#{id}")
    Integer findPermissionContentById(Integer id);
    @Delete("DELETE FROM  t_permission WHERE id=#{id}")
    void deletePermissionById(Integer id);
    @Select("select id from t_role where keyword=#{user}")
    Integer findIdByRole(String keyword);
     @Insert("insert into t_role_permission values(#{rid},#{pid})")
    void addPerConentAndRole(@Param("rid") Integer rid,@Param("pid") Integer pid);
}
